import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.Dictionary;
import java.util.Hashtable;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.BevelBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


public class SpinSlider extends JPanel {
	JLabel label;
	JSpinner spinner;
	JSlider slider;
	
	public SpinSlider(String title, int min, int max, int value)
	{
		JLabel label = new JLabel(title);
		label.setForeground(Color.BLUE);
		label.setAlignmentX(CENTER_ALIGNMENT);
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
		spinner = new JSpinner();
		slider = new JSlider(JSlider.VERTICAL, min, max, value);
		slider.setPaintLabels(true);
		slider.setPaintTicks(true);
		slider.setMajorTickSpacing(10);
		slider.setPreferredSize(new Dimension(60,600));
		slider.addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent e) {
				JSlider s = (JSlider) e.getSource();
				spinner.setValue(s.getValue());
				
			}
		});
		this.add(slider);
		spinner.setModel(new SpinnerNumberModel(value,min,max,1));
		spinner.setEditor(new JSpinner.NumberEditor(spinner));
		spinner.addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent e) {
				JSpinner s = (JSpinner)e.getSource();
				slider.setValue((Integer) s.getValue());
				
			}
			
		});
		this.add(label);
		this.add(spinner);
	}

	public void setName(String name)
	{
		slider.setName(name);
	}
	public void setValue(int value)
	{
		slider.setValue(value);
	}
	public int getValue()
	{
		
		return slider.getValue();
	}
	public void setSize( int width, int height)
	{
		slider.setPreferredSize(new Dimension(width,height));
	}
	public void setMaximum(int max)
	{
		slider.setMaximum(max);
	}
	public int getMaximum()
	{
		return slider.getMaximum();
	}
	public void setMinimum(int min)
	{
		slider.setMinimum(min);
	}
	public int getMinimum()
	{
		return slider.getMinimum();
		
	}
	
	public void setLabelTable(Dictionary labels)
	{
		slider.setLabelTable(labels);
	}
	public Hashtable createStandardLabels(int inc)
	{
		return slider.createStandardLabels(inc);
	}
	public void setMinorTickSpacing(int spacing)
	{
		slider.setMinorTickSpacing(spacing);
	}
	public void setMajorTickSpacing(int spacing)
	{
		slider.setMajorTickSpacing(spacing);
	}
	public int getMajorTickSpacing()
	{
		return slider.getMajorTickSpacing();
	}
	public JSlider getSlider()
	{
		return slider;
	}
	
}
